package com.uwantsoft.business.service.domain.park.search;

import com.uwantsoft.business.service.domain.park.Park;
import com.uwantsoft.business.service.domain.park.search.query.DefaultNearbyParkQuerier;
import com.uwantsoft.business.service.domain.park.search.query.NearbyParkQuerier;
import com.uwantsoft.business.service.domain.park.search.rate.DefaultParkRater;
import com.uwantsoft.business.service.domain.park.search.rate.ParkRater;
import com.uwantsoft.business.service.domain.park.search.statusupdator.GuardConfirmationParkStatusUpdator;
import com.uwantsoft.business.service.domain.park.search.statusupdator.ParkStatusUpdator;
import com.uwantsoft.business.service.domain.user.Driver;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created by Zhang Hui on 2015/5/11.
 */
public class DefaultParkSearcher implements ParkSearcher {

    private List<SearchedPark> parks;
    ;
    private NearbyParkQuerier nearbyParkQuerier = new DefaultNearbyParkQuerier();
    private ParkRater parkRater = new DefaultParkRater();


    @Override
    public List<SearchedPark> search(Driver driver, String region, String latitude, String longitude) {
        parks = nearbyParkQuerier.query(region, latitude, longitude);
        GuardConfirmationParkStatusUpdator parkStatusUpdator = new GuardConfirmationParkStatusUpdator(parks);
        parkStatusUpdator.update();

        rate();

        Collections.sort(parks);
        return parks;
    }

    private void rate() {
        for (SearchedPark park : parks) {
            parkRater.rate(park);
        }
    }


}
